package com.java_foundation.huawei.Test_4;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * @program: java_foundation
 * @description: 数据表记录包含表索引和数值（int范围的整数），请对表索引相同的记录进行合并，即将相同索引的数值进行求和运算，输出按照key值升序进行输出。
 * @author: xiongbangwen <Email>xiongbangwen@163.com</Email>
 * @create: 2020-08-02 21:47
 **/
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        Map<Integer, Integer> treeMap = new TreeMap<Integer, Integer>();
        while (num != 0) {
            num--;
            int key = sc.nextInt();
            int value = sc.nextInt();
            if (!treeMap.containsKey(key)) {
                treeMap.put(key, value);
            } else {
                treeMap.put(key, value + treeMap.get(key));
            }
        }
        for (Integer key : treeMap.keySet()) {
            System.out.println(key + " " + treeMap.get(key));
        }
    }
}

